﻿<%@ page contentType="text/html; charset=UTF-8"%>
<%@include file="/sys_include.jsp"%>

<div style="padding: 4px;">
内容
   <input id="s_qfword_data_content" name="s_qfword_data_content" type="text">&nbsp;&nbsp;
类型
   <select id="s_qfword_data_subtype" name="s_qfword_data_subtype" class="easyui-combobox" style="width:256px;">
       <option value="">全部</option>
       <option value="招财">招财</option>
       <option value="事业">事业</option>
       <option value="升学">升学</option>
       <option value="爱情">爱情</option>
       <option value="求子">求子</option>
       <option value="四季平安">四季平安</option>
       <option value="辟邪">辟邪</option>
       <option value="安康">安康</option>
       <option value="福禄">福禄</option>
       <option value="长寿">长寿</option>
   </select>

   <input id="s_qfword_data_query_btn" type="button" value="查  询">
</div>

<div style="padding: 4px;"><table id="qfword_data_grid" width="100%"></table></div>
<div id="qfword_data_grid_page" style="padding: 4px;"></div>



<div id="qfword_data_window" class="easyui-dialog" title="新增内容">
   <form id="qfword_data_form" name="qfword_data_form" method="POST">
      <div id="qfword_data_errmsg"></div>

      <table width="100%" align="center">
         <tr>
            <td align="right">类型</td>
            <td align="left">
               <select id="qfword_data_subtype" name="qfword_data_subtype" class="easyui-combobox" style="width:64px;">
                   <option value="招财">招财</option>
                   <option value="事业">事业</option>
                   <option value="升学">升学</option>
                   <option value="爱情">爱情</option>
                   <option value="求子">求子</option>
                   <option value="四季平安">四季平安</option>
                   <option value="辟邪">辟邪</option>
                   <option value="安康">安康</option>
                   <option value="福禄">福禄</option>
                   <option value="长寿">长寿</option>
               </select>
            </td>
         </tr>
         <tr>
            <td align="right">内容：</td>
            <td align="left">
               <textarea id="qfword_data_content" name="qfword_data_content" rows="8" cols="64"></textarea>
            </td>
         </tr>

         <tr>
            <td colspan="2" align="center">
               <input type="button" id="qfword_data_submit_btn" value="提　交"/>&nbsp;&nbsp;
               <input type="button" id="qfword_data_close_btn" value="关　闭"/>
            </td>
         </tr>
      </table>
   </form>
</div>


<script>
   closeUIDialog('qfword_data_window');

   jQuery("#qfword_data_grid").jqGrid(
   {
      caption :
         '<a href="javascript:fun_qfword_add()"  class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-edit\'">新增</a>' +
         '<a href="javascript:fun_qfword_update()" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-save\'">修改</a>' +
         '<a href="javascript:fun_qfword_delete()" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-cancel\'">删除</a>',
      datatype: "json",
      hidegrid: false, //不显示收缩
      autowidth: true,
      url:'data/Qfdtext/list.do?s_textType=2', //请求后台返回列表数据的URL
      height: '100%',
      forceFit: true,//调整宽度不改变表格宽度
      width: '100%',
      colNames:[ '编号', '内容', '类型'],
      //sortable:设置该字段是否进行排序,sorttype:排序的数据类型
      colModel:[
      {name:'textId',index:'textId', width:1,sorttype:'int',sortable:false},
      {name:'textContent',index:'textContent',width:240,sortable:false},
      {name:'textSubtype',index:'textSubtype',width:80,sortable:false}
      ],
      multiselect: false,
      toolbar:[false,'top'],
      rowNum: 15,
      rowList:[15, 50, 100],
      rownumbers : true,
      viewrecords: true,
      sortname:  "textId",
      sortorder: "desc",
      pager: '#qfword_data_grid_page',
      jsonReader: {
         root: 'dataRows',
         repeatitems : false
      }
   });
   jQuery("#qfword_data_grid").jqGrid('hideCol', ['textId']);

   $('#qfword_data_close_btn').unbind('click');
   $('#qfword_data_close_btn').click(function()
   {
      closeUIDialog('qfword_data_window');
   });

   $('#qfword_data_submit_btn').unbind('click');
   $('#qfword_data_submit_btn').click(function()
   {
      fun_qfword_data_submit();
   });

   var qfword_data_saveflag = true;

   function fun_qfword_add()
   {
      $("#qfword_data_form")[0].reset();
      qfword_data_saveflag = true;

      openUIDialog('qfword_data_window', true, 640, 320);
   }

   var qfword_data_select_row;

   function fun_qfword_update()
   {
      var gr =$("#qfword_data_grid").jqGrid('getGridParam','selrow');
      if(gr != null)
      {
         $("#qfword_data_form")[0].reset();
          qfword_data_select_row = jQuery("#qfword_data_grid").jqGrid('getRowData', gr);
         fun_qfword_data_load_data(qfword_data_select_row);

         qfword_data_saveflag = false;
         openUIDialog('qfword_data_window', true, 640, 320);
      }
      else
      {
         $.messager.alert('提示','请先选中一行数据!!');
      }
   }

   function fun_qfword_data_load_data(rowData)
   {
      $("#qfword_data_subtype").val(rowData.textSubtype);
      $("#qfword_data_content").val(rowData.textContent);
   }

   function fun_qfword_data_submit()
   {
      var qfdtextJson = new Object();
      qfdtextJson.textType = 2;
      qfdtextJson.textContent = $('#qfword_data_content').val();
      qfdtextJson.textSubtype = $('#qfword_data_subtype').val();

      if(qfword_data_saveflag)
      {
         qfdtextJson.infoId = '';

         $.ajax(
         {
            async : false,
            type : "POST",
            url : "data/Qfdtext/save.do",
            data :
            {
               qfdtextJson : JSON.stringify(qfdtextJson)
            },
            dataType : "json",
            contentType : "application/x-www-form-urlencoded; charset=UTF-8",
            success : function(json)
            {
               if (json.success)
               {
                  $("#qfword_data_grid").trigger("reloadGrid");
                  $.messager.alert('操作提示', '操作成功！');
               }
               else
               {
                  $.messager.alert('操作提示', '操作失败，请重试！');
               }
            }
         });
      }
      else
      {
         qfdtextJson.infoId = qfword_data_select_row.textId;

         $.ajax(
         {
            async : false,
            type : "POST",
            url : "data/Qfdtext/update.do",
            data :
            {
               qfdtextJson : JSON.stringify(qfdtextJson)
            },
            dataType : "json",
            contentType : "application/x-www-form-urlencoded; charset=UTF-8",
            success : function(json)
            {
               if (json.success)
               {
                  $("#qfword_data_grid").trigger("reloadGrid");
                  $.messager.alert('操作提示', '操作成功！');
               }
               else
               {
                  $.messager.alert('操作提示', '操作失败，请重试！');
               }
            }
         });
      }

      closeUIDialog('qfword_data_window');
   }

   function fun_qfword_delete()
   {
      var gr = $("#qfword_data_grid").jqGrid('getGridParam','selrow');
      if(gr != null)
      {
         var rowData = jQuery("#qfword_data_grid").jqGrid('getRowData', gr);
         $.messager.confirm('删除提示','您确认要删除?', function(r)
         {
            if(r)
            {
               fun_qfword_del(rowData.textId);
            }
         });
      }
      else
      {
         $.messager.alert('提示','请先选中一行数据!!');
      }
   }

   function fun_qfword_del(jwdtids)
   {
      $.ajax(
      {
          async : false,
         type : "POST",
         url : "data/Qfdtext/delete.do",
         dataType : "json",
         data :
         {
            ids : jwdtids
         },
         success : function(json)
         {
            if (json.success)
            {
               $("#qfword_data_grid").trigger("reloadGrid");
               $.messager.alert('操作提示', '操作成功！');
            }
            else
            {
               $.messager.alert('操作提示', '操作失败，请重试！');
            }
         }
      });
   }

   $('#s_qfword_data_query_btn').unbind('click');
   $('#s_qfword_data_query_btn').click(function()
   {
      var s_textType = 2;
      var s_textSubtype = $('#s_qfword_data_subtype').combobox('getValue');
      var s_textContent = $('#s_qfword_data_content').val();

      $("#qfword_data_grid").setGridParam(
      {
         url : 'data/Qfdtext/list.do',
         mtype: 'post',
         postData:{'s_textType':s_textType, 's_textSubtype':s_textSubtype, 's_textContent':s_textContent}
      });

      $("#qfword_data_grid").trigger("reloadGrid");
   });

</script>
